﻿<EditDataFormTemplateSpec 
	xmlns="bb_appfx_editdataformtemplate"
	xmlns:common="bb_appfx_commontypes" 
	ID="afd633d2-1f68-488e-8956-6b8983aec1e2" 
	Name="ProspectTeam Edit Data Form"
	Description="Prospect Team Edit Data Form" 
	Author="Blackbaud Professional Services"
	DataFormInstanceID="d8327451-2725-42d3-9641-3a94cb0535db" 
	RecordType="ProspectTeam"
	common:SecurityUIFolder="Service Bus Adapter"
	>

    <SPDataForm>

      <!-- define the edit load SP, which is used to load the data for the form -->
      <LoadImplementation SPName="USP_DATAFORMTEMPLATE_EDITLOAD_PROSPECTTEAM_CUSTOM">
        <common:CreateProcedureSQL>
          <![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_EDITLOAD_PROSPECTTEAM_CUSTOM(
  @ID uniqueidentifier,
  @FundraiserId uniqueidentifier = null output,
  @DATALOADED bit = 0 output,
  @TSLONG bigint = 0 output,
  @DateFrom datetime = null output,
  @DateTo datetime = null output
  
)
as

	set nocount on;

	-- be sure to set these, in case the select returns no rows
	set @DATALOADED = 0
	set @TSLONG = 0

	-- populate the output parameters, which correspond to fields on the form.  Note that
	-- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system
	-- will display a "no data loaded" message.  Also note that we fetch the TSLONG so that concurrency
	-- can be considered.
	select
		@DATALOADED = 1,
		@TSLONG = TSLONG	from dbo.PROSPECT
	where ID = @ID

	return 0;
				]]>
        </common:CreateProcedureSQL>
      </LoadImplementation>

      <SaveImplementation SPName="USP_DATAFORMTEMPLATE_EDIT_PROSPECTTEAM_CUSTOM">
        <common:CreateProcedureSQL>
          <![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_EDIT_PROSPECTTEAM_CUSTOM (
@ID uniqueidentifier,
@FundraiserId uniqueidentifier,
@DateFrom datetime,
@DateTo datetime


)
as

	set nocount on;

DECLARE @CHANGEAGENTID uniqueidentifier

	if @CHANGEAGENTID is null  
		exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
				
	declare @CURRENTDATE datetime
	set @CURRENTDATE = getdate()


	begin try
    
    UPDATE PROSPECTTEAM
    SET
    DATEFROM = @DateFrom,
    DATETO = @DateTo

    WHERE PROSPECTID = @ID AND MEMBERID = @FundraiserID


	end try
	begin catch
		exec dbo.USP_RAISE_ERROR
		return 1
	end catch

return 0;
				]]>
        </common:CreateProcedureSQL>
      </SaveImplementation>

    </SPDataForm>

    <!-- describe fields on the form, which correspond to parameters on the SP.  Note that system paramters 
	like the record ID, DATALOADED, TSLONG, and CURRENTAPPUSERID need not be listed. -->
    <common:FormMetaData FixedDialog="true">
      <common:FormFields>
        <common:FormField FieldID="FundraiserId" Caption="Fundraiser Id" DataType="Guid" />        
        <common:FormField FieldID="DateFrom" Caption="Date From" DataType="Date" />
        <common:FormField FieldID="DateTo" Caption="Date To" DataType="Date" />

      </common:FormFields>

    </common:FormMetaData>

  </EditDataFormTemplateSpec>